/*
 * Copyright 2008-2012 Centro Andaluz de Innovación y Tecnologías de la
 * Información y las Comunicaciones (CITIC). All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 *
 * Please contact CITIC - Edificio CITIC, C/ Marie Curie, 6 Parque
 * Tecnológico de Andalucía 29590 - Campanillas, Málaga, Spain
 * or visit www.citic.es, if you need additional information or
 * have any questions.
 */

package es.citic.puedes.youtube.testhelp;

import java.util.Iterator;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import es.citic.puedes.youtube.model.StandarVideos;
import es.citic.puedes.youtube.model.UserPreferences;
import es.citic.puedes.youtube.model.YouTubeContact;
import es.citic.puedes.youtube.model.YouTubePlayList;
import es.citic.puedes.youtube.model.YouTubePlayListEntry;
import es.citic.puedes.youtube.model.YouTubePreferences;
import es.citic.puedes.youtube.model.YouTubeResult;
import es.citic.puedes.youtube.model.YouTubeUser;
import es.citic.puedes.youtube.model.YouTubeVideo;
import es.citic.puedes.youtube.model.YouTubeVideoMinimal;

/**
 * 
 * class for testing the YouTubeManager Service
 * 
 * 
 */

public class YouTubePrinterTestMethods {

	// Log instance
	final static Logger logger = LoggerFactory.getLogger(YouTubePrinterTestMethods.class);

	/**
	 * prints the profile of a YouTube user
	 * 
	 * @param userProfile
	 */
	public static void printProfile(YouTubeUser userProfile) {

		logger.info("USER PROFILE:");

		if (userProfile != null) {

			logger.info("Description: " + userProfile.getDescription());
			logger.info("Age: " + userProfile.getAge());
			logger.info("Name: " + userProfile.getName());
			logger.info("LastName: " + userProfile.getLastName());
			logger.info("Company: " + userProfile.getCompany());
			logger.info("fotolink: " + userProfile.getFotoLink());

			if (userProfile.getStatus() != null) {
				logger.info("Single?: "+ userProfile.getStatus());
			}

			logger.info("Music: " + userProfile.getMusic());
			logger.info("Movies: " + userProfile.getMovies());
			logger.info("Occupation: " + userProfile.getOccupation());
			logger.info("Hobbies: " + userProfile.getHobbies());
			logger.info("Hometown: " + userProfile.getHome());

			if (userProfile.getGender() != null) {
				logger.info("Gender: "+ userProfile.getGender());
			}

			logger.info("Username: " + userProfile.getUserName());
			logger.info("Password: " + userProfile.getPassword());
			logger.info("UserId: " + userProfile.getUserId());
			logger.info("YouTubeId: " + userProfile.getYouTubeId());
		}
		logger.info("");
		logger.info("");
	}

	/**
	 * prints the list of videos or playlist from a YouTube search
	 * 
	 * @param result
	 */
	public static void printModelResultList(YouTubeResult result) {

		if (result != null) {

			List<YouTubeVideoMinimal> videoMinimalList = result.getVideos();

			// logger.info("Found Videos: ");

			if (videoMinimalList.isEmpty()) {
				logger.info("no videos found. \n");
			} else {
				printModelVideoMinimalList(videoMinimalList, "Found Videos: ");
			}

			List<YouTubePlayList> playLists = result.getPlayLists();
			logger.info("Found playLists: ");

			if (playLists.isEmpty()) {
				logger.info("no playlists found. \n");
			} else {
				printModelPlayLists(playLists);
			}

		}
	}

	/**
	 * prints a list of YouTube playlists
	 * 
	 * @param playLists
	 */
	public static void printModelPlayLists(List<YouTubePlayList> playLists) {

		if (!playLists.isEmpty()) {
			Iterator<YouTubePlayList> playlistsIterator = playLists.iterator();
			logger.info("PLAYLISTS FROM USER: ");
			logger.info("total entries: " + playLists.size());

			int i = 1;
			while (playlistsIterator.hasNext()) {
				YouTubePlayList currentPlayList = new YouTubePlayList();
				currentPlayList = playlistsIterator.next();

				logger.info("element: " + i);
				logger.info("playlist title: "	+ currentPlayList.getTitle());
				logger.info("total entries of playlist: "+ currentPlayList.getTotalResults());
				logger.info("playlist url: " + currentPlayList.getUrl());
				logger.info("playlist author: "	+ currentPlayList.getAuthors());
				logger.info("playlist description: "	+ currentPlayList.getDescription());
				logger.info("playlist id: "	+ currentPlayList.getPlaylistId() + "\n");
				i++;
			}
		} else {
			logger.info("no playlists from user ");
		}

	}

	/**
	 * prints the entries of a YouTube playlist
	 * 
	 * @param playListEntries
	 */
	public static void printModelPlayListEntriesFromPlayList(
			List<YouTubePlayListEntry> playListEntries) {

		logger.info("ENTRIES FROM A PLAYLIST: ");

		if (!playListEntries.isEmpty()) {

			Iterator<YouTubePlayListEntry> playlistsIterator = playListEntries
					.iterator();

			logger.info("total entries: " + playListEntries.size());

			int i = 1;

			while (playlistsIterator.hasNext()) {
				YouTubePlayListEntry currentPlayListEntry = new YouTubePlayListEntry();
				currentPlayListEntry = playlistsIterator.next();

				logger.info("element:" + i);
				logger.info("video title in the playlist: "+ currentPlayListEntry.getTitle());
				logger.info("video thumbnail in the playlist: "+ currentPlayListEntry.getThumbnail());
				logger.info("video id in the playlist: "+ currentPlayListEntry.getVideoId());
				logger.info("video description in the playlist: "+ currentPlayListEntry.getDescription());
				logger.info("video position in the playlist: "+ currentPlayListEntry.getPosition());
				logger.info("video url in the playlist: "+ currentPlayListEntry.getUrl() + "\n");
				i++;
			}
		} else {

			logger.info("empty playlist ");
		}

	}

	/**
	 * prints a YouTube video
	 * 
	 * @param youTubeVideo
	 */
	public static void printModelVideo(YouTubeVideo youTubeVideo) {

		logger.info("VIDEO:");

		if (youTubeVideo != null) {

			logger.info("video title: " + youTubeVideo.getTitle());
			logger.info("video authors: " + youTubeVideo.getAuthors());
			logger.info("video categories: " + youTubeVideo.getCategories());
			logger.info("video thumbnail: "	+ youTubeVideo.getThumbnail());
			logger.info("video description: "+ youTubeVideo.getDescription());
			logger.info("video url: " + youTubeVideo.getUrl());
			logger.info("video Rating: " + youTubeVideo.getRating());
			logger.info("video ViewCount: "	+ youTubeVideo.getViewCount());

			if (youTubeVideo.getComments().isEmpty()) {
				logger.info("video Comments: no comments for this video");
			} else {
				logger.info("video Comments: " + youTubeVideo.getComments());
			}
			logger.info("video KeyWords: " + youTubeVideo.getKeyWords());
			logger.info("video Publication State: "	+ youTubeVideo.getPublicationState());
			logger.info("video was published: "	+ youTubeVideo.getPublished().getTime().toString());
			logger.info("video duration: " + youTubeVideo.getDuration()	+ "\n");
		}
	}

	/**
	 * prints a video minimal list
	 * 
	 * @param youTubeVideoMinimalList
	 */
	public static void printModelVideoMinimalList(
			List<YouTubeVideoMinimal> youTubeVideoMinimalList, String kindOfList) {

		Iterator<YouTubeVideoMinimal> youTubeVideoListIterator = youTubeVideoMinimalList
				.iterator();

		YouTubeVideoMinimal currentYouTubeVideoMinimal = null;

		logger.info(kindOfList);
		logger.info(kindOfList);
		logger.info("total entries: " + youTubeVideoMinimalList.size());
		logger.info("total entries: " + youTubeVideoMinimalList.size());

		int i = 1;

		while (youTubeVideoListIterator.hasNext()) {

			currentYouTubeVideoMinimal = youTubeVideoListIterator.next();

			logger.info("entra en el video "+i);
			logger.info("element: " + i);
			logger.info("video title: "+ currentYouTubeVideoMinimal.getTitle());
			logger.info("video id: "+ currentYouTubeVideoMinimal.getVideoId());
			logger.info("video url: "+ currentYouTubeVideoMinimal.getUrl());
			logger.info("video thumbnail: "	+ currentYouTubeVideoMinimal.getThumbnail());
			logger.info("video keywords: "+ currentYouTubeVideoMinimal.getKeywords());

			// logger.info("video description: "
			// + currentYouTubeVideoMinimal.getDescription() + "\n");

			i++;

			logger.info("\n");

		}
	}

	/**
	 * prints a preference list
	 * 
	 * @param userPreferences
	 */
	public static void printPreferences(UserPreferences userPreferences) {

		if (userPreferences.getPreferences().isEmpty()) {

			logger.info("no preferences for this user ");

		} else {

			Iterator<YouTubePreferences> userPreferencesIterator = userPreferences.getPreferences().iterator();
			YouTubePreferences currentPreference = null;

			logger.info("preferences for this user: ");

			while (userPreferencesIterator.hasNext()) {
				currentPreference = userPreferencesIterator.next();

				logger.info("preference name: "+ currentPreference.getName());
				logger.info("preference value: "+ currentPreference.getValue() + "\n");
			}
		}

	}

	/**
	 * prints the standard videos
	 * 
	 * @param standarVideos
	 */
	public static void printStandardVideos(StandarVideos standarVideos) {

		List<YouTubeVideoMinimal> mostViewedVideoList = standarVideos.getMostViewed();
		// logger.info("most viewed videos found: ");

		if (mostViewedVideoList.isEmpty()) {
			logger.info("no most viewed videos found. \n");
		} else {
			printModelVideoMinimalList(mostViewedVideoList,"most viewed videos found: ");
		}

		List<YouTubeVideoMinimal> recentVideoList = standarVideos.getRecent();
		// logger.info("\n\nrecent videos found: ");

		if (recentVideoList.isEmpty()) {
			logger.info("no recent videos found. \n");
		} else {
			printModelVideoMinimalList(recentVideoList,"\n\nrecent videos found: ");
		}

	}

	/**
	 * prints a list of YouTube contacts
	 * 
	 * @param contactList
	 */
	public static void printContactList(List<YouTubeContact> contactList,
			String username) {
		Iterator<YouTubeContact> contactListIterator = contactList.iterator();

		logger.info("contacts from " + username + ": ");
		while (contactListIterator.hasNext()) {
			printContact(contactListIterator.next());
		}
		logger.info("\n");
	}

	/**
	 * prints a YouTube contact
	 * 
	 * @param contact
	 */
	public static void printContact(YouTubeContact contact) {

		logger.info("contact username: " + contact.getUserName());
		logger.info("contact email: " + contact.getEmail());
		logger.info("contact status: " + contact.getStatus());

	}

}
